﻿cmake_minimum_required(VERSION 2.8)
project(protobuf_parser)
macro(group_src_by_dir SRC_LIST)
    foreach(SRC_PATH ${${SRC_LIST}})
        string(REGEX REPLACE ${CMAKE_CURRENT_SOURCE_DIR}\(.*\) \\1 RELATIVE_PATH ${SRC_PATH})
        #message(STATUS ${RELATIVE_PATH})
        string(REGEX REPLACE "(/..)*/(.+)/..+" \\2 GROUP_NAME ${RELATIVE_PATH})
        #message(STATUS ${GROUP_NAME})
        if(NOT RELATIVE_PATH STREQUAL GROUP_NAME)
            string(REPLACE "/" "\\" GROUP_NAME ${GROUP_NAME})
            source_group(${GROUP_NAME} FILES ${SRC_PATH})
        else()
            source_group("" FILES ${SRC_PATH})
        endif()
    endforeach(SRC_PATH)
endmacro(group_src_by_dir)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "list of supported configurations." FORCE)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/../bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/../bin)
include_directories(${PROJECT_SOURCE_DIR}/../inc)
include_directories(${PROJECT_SOURCE_DIR}/pb)
link_directories(${PROJECT_SOURCE_DIR}/../thirdparty/lib)

if(WIN32)
	add_compile_options(/W3 /WX /MT)
	add_compile_options(/wd4146)
elseif(UNIX)
	add_compile_options(-Wall -Werror -std=c++11)
endif(WIN32)

if(WIN32)
	link_libraries(libprotobuf)
elseif(UNIX)
	link_libraries(protobuf)
endif(WIN32)
file(GLOB_RECURSE src_files "*.c" "*.cc" "*.cpp" "*.h" "*.hpp" "../proto/*.proto")
if(WIN32)
	group_src_by_dir(src_files)
endif(WIN32)
add_executable(${PROJECT_NAME} ${src_files})
set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX "_d")
